package fy.mdm.dao;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.soa.eis.adapter.framework.exception.EisException;
import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.GroupRecord;
import com.soa.eis.adapter.framework.message.impl.MsgObject;
import com.soa.eis.adapter.framework.requester.IServiceRequester;
import com.soa.eis.adapter.framework.requester.impl.BaseServiceRequester;

import fy.mdm.bean.FiexdAssetBean;

public class FiexdAssetReviewDao {
	private FiexdAssetBean fiexdAssetBean;
	
	private static Log log = LogFactory.getLog(FiexdAssetReviewDao.class);
//	private String assettypes;// 资产类型转化

//	private List<String> shu = new ArrayList<String>();
	
//	public static void main(String[] args) {
//		IServiceRequester Requester = null;
//		try {
//			Requester = BaseServiceRequester.getInstance();
//		} catch (EisException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		System.out.println(Requester);
//	}
	public boolean StateReturn() throws Exception {
		try {
			
//			String shu2="M00004";
//			String shu3="M00008";
//			shu.add(shu2);
//			shu.add(shu3);

//			System.out.println(this.fiexdAssetBean.getNumberList().size());
//			for (int i = 0; i < this.shu.size(); i++) {
			for (int i = 0; i < this.fiexdAssetBean.getNumberList().size(); i++) {

				IServiceRequester Requester = BaseServiceRequester.getInstance();
				List<GroupRecord> grs1 = new ArrayList<GroupRecord>();//多层用
				// 定义请求报文对象
				IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
				String SourceSysID = "06004"; // 请求方(发布方)
				String ServiceID = "06001000000031";// 响应方(发布方)
				// 获取系统时间
				Date date = new Date();
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
				String format = simpleDateFormat.format(date);
				// 对请求报文对象进行设置
				reqMo.setSourceSysID(SourceSysID); // 设置报文 请求方系统号
				reqMo.setSerialNO(format.substring(0, 8) + SourceSysID
						+ String.format("%06d", ++MaterialRequestNoTimerTask.requestNo));// 设置报文流水号,第三段表示今天发送的第几的一次报文
				reqMo.setServiceID(ServiceID); // 设置报文 提供方服务号
				reqMo.setServiceDateTime(format); // 设置报文 日期时间
				
				reqMo.setReqValue("BOID","MDM_EQUIPMENT_F" );

				GroupRecord gr1 = new GroupRecord();
				gr1.setName("ROW");
				gr1.setFieldValue("EQUIPMENT_CODE", this.fiexdAssetBean.getNumberList().get(i));//设备条码
//				gr1.setFieldValue("EQUIPMENT_CODE", this.shu.get(i));//设备条码
//				gr1.setFieldValue("", fiexdAssetBean.getSupplier());// 子公司
				gr1.setFieldValue("ASSET_TYPE", fiexdAssetBean.getAssettypes());//资产类型
//				gr1.setFieldValue("ASSET_TYPE","2");//资产类型
//				gr1.setFieldValue("", fiexdAssetBean.getBusiness());//业务类型
				gr1.setFieldValue("ASSET_NUMBERS", fiexdAssetBean.getAssetnumbers());//固定资产编号
//				gr1.setFieldValue("ASSET_NUMBERS", "999999");//固定资产编号
//				gr1.setFieldValue("", fiexdAssetBean.getSupplier());//供应商
//				gr1.setFieldValue("", fiexdAssetBean.getNumber());
				grs1.add(gr1);
				reqMo.setReqGroupRecord(grs1);


				log.info("reqMo:"+reqMo);
				
				IMsgObject respMo = null;
				respMo = Requester.execute(reqMo);//发布报文
//				log.info("respMo:"+respMo);
//				 System.out.println(respMo+"22");
			}
			StateReturn2();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return true;
		
	}
	public boolean StateReturn2() throws Exception {
		try {
			
//			String shu2="M00003";
//			String shu3="M00001";
//			shu.add(shu2);
//			shu.add(shu3);

//			System.out.println(this.fiexdAssetBean.getNumberList().size());
//			for (int i = 0; i < this.shu.size(); i++) {
			for (int i = 0; i < this.fiexdAssetBean.getNumberList().size(); i++) {

				IServiceRequester Requester = BaseServiceRequester.getInstance();
//				List<GroupRecord> grs1 = new ArrayList<GroupRecord>();//多层用
				// 定义请求报文对象
				IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
				String SourceSysID = "06004"; // 请求方(发布方)
				String ServiceID = "03003000000071";// 响应方(发布方)
				// 获取系统时间
				Date date = new Date();
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
				String format = simpleDateFormat.format(date);
				// 对请求报文对象进行设置
				reqMo.setSourceSysID(SourceSysID); // 设置报文 请求方系统号
				reqMo.setSerialNO(format.substring(0, 8) + SourceSysID
						+ String.format("%06d", ++MaterialRequestNoTimerTask.requestNo));// 设置报文流水号,第三段表示今天发送的第几的一次报文
				reqMo.setServiceID(ServiceID); // 设置报文 提供方服务号
				reqMo.setServiceDateTime(format); // 设置报文 日期时间
				
				reqMo.setReqValue("BOID","MDM_EQUIPMENT_F" );


				reqMo.setReqValue("EQUIPMENT_CODE", this.fiexdAssetBean.getNumberList().get(i));//设备条码
//				reqMo.setReqValue("EQUIPMENT_CODE", this.shu.get(i));//设备条码
//				gr1.setFieldValue("", fiexdAssetBean.getSupplier());// 子公司
				reqMo.setReqValue("ASSET_TYPE", fiexdAssetBean.getAssettypes());//资产类型
//				reqMo.setReqValue("ASSET_TYPE", "2");//资产类型
//				gr1.setFieldValue("", fiexdAssetBean.getBusiness());//业务类型
				reqMo.setReqValue("ASSET_NUMBERS", fiexdAssetBean.getAssetnumbers());//固定资产编号
//				reqMo.setReqValue("ASSET_NUMBERS", "999999");//固定资产编号
//				gr1.setFieldValue("", fiexdAssetBean.getSupplier());//供应商
//				gr1.setFieldValue("", fiexdAssetBean.getNumber());



				log.info("reqMo:"+reqMo);
				
				IMsgObject respMo = null;
				respMo = Requester.execute(reqMo);//发布报文
//				log.info("respMo:"+respMo);
//				 System.out.println(respMo+"33");
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return true;
		
	}
//----------------------------------------------------------


	public void setFiexdAssetBean(FiexdAssetBean fiexdAssetBean) {
		this.fiexdAssetBean = fiexdAssetBean;
	}

//	public String getAssettypes() {
//		return assettypes;
//	}
//
//	public void setAssettypes(String assettypes) {
//		this.assettypes = assettypes;
//	}
	

}
